﻿using System;
using Codingly.NRex;
using NConsoler;
using NRex.Helpers;
using NRex.Logging;

namespace NRex
{
    internal class Program
    {
        private static readonly ILogger _logger = new ColoredConsoleLogger();
        public static ILogger Logger
        {
            get { return _logger; }
        }

        static Program()
        {
            new EmbeddedAssemblyResolver().Activate();
        }

        private static void Main(string[] args)
        {
            try
            {
                Consolery.Run(typeof(Program), args);
            }
            finally
            {
#if DEBUG
                Console.WriteLine("Press any key to quit");
                Console.ReadKey();
#endif
            }
        }

        [Action("Prints a list of the references of an assembly or all assemblies in a directory")]
        public static void list(
            [RequiredAttribute(Description = "assembly file or directory")] string fileOrDirectory
            )
        {
            var lister = new AssemblyReferencesLister(Logger);
            lister.ProcessTarget(fileOrDirectory);
        }

        [Action("Prints referenced assemblies and indicates by who. Highlights potential conficts.")]
        public static void group(
            [RequiredAttribute(Description = "assembly file or directory")] string fileOrDirectory
            )
        {
            var lister = new ReferencedAssembliesLister(Logger);
            lister.ProcessTarget(fileOrDirectory);
        }

        [Action("Prints the dependency tree of an assembly")]
        public static void tree(
            [RequiredAttribute(Description = "assembly file")] string file
            )
        {
            var lister = new DependencyTreeLister(Logger);
            lister.ProcessFile(file);
        }
    }
}